<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <el-form size="mini" label-width="70px" v-formkey="{query:toQuery}">
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="类型">
                <el-select v-model="query.type" class="edit-input" placeholder="请选择" style="width:100%">
                  <el-option
                      v-for="(item,index) in dict.t_bas_settlement_type"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="状态">
                <el-select v-model="query.status" class="edit-input" placeholder="请选择" style="width:100%">
                  <el-option
                      v-for="(item,index) in dict.common_status"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="编码">
                <el-input v-model="query.code" placeholder="输入编码进行搜索"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="名称">
                <el-input v-model="query.name" placeholder="输入名称进行搜索"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <rrOperation :crud="crud"/>
      </div>
      <crudOperation :permission="permission" />
    </div>
    <div class="body-container">

      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0"
                 :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="mini" label-width="100px">
          <el-form-item label="编码">
            <el-input v-model="form.code" style="width: 370px;"/>
          </el-form-item>
          <el-form-item label="名称">
            <el-input v-model="form.name" readOnly disabled style="width: 370px;"/>
          </el-form-item>
          <el-form-item label="结算方式类型">
            <el-select v-model="form.type" class="edit-input" placeholder="请选择" style="width: 370px;">
              <el-option
                  v-for="(item,index) in dict.t_bas_settlement_type"
                  :key="index"
                  v-if="item.seq>0"
                  :label="item.label"
                  :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="结算天数" prop="settlementDayCount" v-if="form.type!=3">
            <el-input v-model="form.settlementDayCount" style="width: 370px;"/>
          </el-form-item>
          <el-form-item label="结算日" prop="settlementDay" v-if="form.type==1 || form.type==4">
            <el-input v-model="form.settlementDay" style="width: 370px;"/>
          </el-form-item>
          <el-form-item label="排序">
            <el-input-number v-model="form.seq" :min="1" label="排序" style="width: 370px;"></el-input-number>
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="form.status" class="edit-input" placeholder="请选择" style="width: 370px;">
              <el-option
                  v-for="(item,index) in dict.common_status"
                  :key="index"
                  v-if="item.seq>0"
                  :label="item.label"
                  :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" type="textarea" style="width: 370px;"/>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>

      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu>
      <!-- 表格配置 -->
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header"  @tabSave="tabSave" @pit="pit" />
      </el-dialog>

      <!--表格渲染-->
      <el-table ref="table"  border
                height="700"
                show-summary
                @cell-dblclick="row=>crud.toEdit(row)"
                v-loading="crud.loading"
                :data="crud.data"
                size="small"
                style="width: 100%;"
                v-if="isShowTable"
                @header-dragend="changeColWidth"
                @contextmenu.native="showMenu"
                :summary-method="crud.sumRow"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column :render-header="crud.renderHeader" type="selection" width="60"/>
        <el-table-column :render-header="crud.renderHeader" type="index" width="60" label="序号"/>
        <el-table-column
          v-if="item.visible"
          v-for="(item, index) in crud.header"
          :key="`col_${index}`"
          :prop="item.prop"
          :label="columnLabel(item)"
          :width="item.width + 'px'"
          :data-porp='item.prop'
          @contextmenu.native="showMenu"
          @header-dragend="changeColWidth"
        >
          <!-- 自定义渲染模版 -->
          <template slot-scope="scope">
            <!-- 当列key为 sort 时，渲染一个手柄icon -->
            <template v-if="item.prop =='sort'">
              <div class="handle_move">
                <i :class="scope.row['sort']" />
              </div>
            </template>
            <template v-else>
              <span v-if="item.type == 1" style="margin-left: 0px">{{scope.row[`${item.prop}`]}}</span>
              <span v-if="item.type == 2" style="margin-left: 0px">{{ parseTime(scope.row[`${item.prop}`])}}</span>
              <span v-if="item.type == 3" style="margin-left: 0px">{{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}</span>
            </template>
          </template>
        </el-table-column>
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('code')" prop="code" label="编码"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('name')" prop="name" label="名称"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('type')" prop="type" label="结算方式类型">-->
<!--          <template slot-scope="scope">-->
<!--            {{ dict.label.t_bas_settlement_type[scope.row.type] }}-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('settlementDayCount')" prop="settlementDayCount" label="结算天数"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('settlementDay')" prop="settlementDay" label="结算日"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('status')" prop="status" label="状态">-->
<!--          <template slot-scope="scope">-->
<!--            {{ dict.label.common_status[scope.row.status] }}-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('remark')" prop="remark" label="备注"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-permission="['admin','basSettlement:edit','basSettlement:del']" label="操作" width="150px"-->
<!--                         align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <udOperation-->
<!--                :data="scope.row"-->
<!--                :permission="permission"-->
<!--            />-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination/>
    </div>
  </div>
</template>

<script>
import crudBasSettlement from '@/api/erp/basSettlement'
import CRUD, {crud, form, header, presenter} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

import { publicListKey } from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
import {tablemixins} from "@/mixins/tablemixins";
import  jTableColumnConfig  from "@/components/jTableColumnConfig/jTableColumnConfig";

// crud交由presenter持有
const defaultCrud = CRUD({title: '结算方式', url: 'api/basSettlement', sort: 'code,asc', crudMethod: {...crudBasSettlement}})
const defaultForm = {
  id: null,
  code: null,
  name: null,
  type: null,
  settlementDayCount: null,
  settlementDay: null,
  seq: null,
  status: null,
  remark: null,
  createUserId: null,
  createUserCode: null,
  createUserName: null,
  createTime: null,
  updateUserId: null,
  updateUserCode: null,
  updateUserName: null,
  updateTime: null
}
export default {
  name: 'BasSettlement',
  components: {pagination, crudOperation, rrOperation, udOperation,jTableColumnConfig},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),publicListKey,tablemixins],
  dicts: ['t_bas_settlement_type', 'common_status'],
  data() {
    return {

      permission: {
        add: ['admin', 'basSettlement:add'],
        edit: ['admin', 'basSettlement:edit'],
        del: ['admin', 'basSettlement:del'],
        import: ['admin', 'basSettlement:import'],
        export: ['admin', 'basSettlement:export'],
        copy: ['admin', 'basSettlement:copy'],
        upload: ['admin', 'basSettlement:upload'],
        download: ['admin', 'basSettlement:download'],
        enable: ['admin', 'basSettlement:enable'],
        disable: ['admin', 'basSettlement:disable'],
      },
      rules: {
        code: [
          {required: true, message: '编码不能为空', trigger: 'blur'}
        ],
        name: [
          {required: true, message: '名称字段说明：该字段输入框不可编辑，取值条件为：{类型}+{天数}+‘天’；当类型选择“现结”时，名称取值为：现结；\n', trigger: 'blur'}
        ],
        settlementDayCount: [
          {required: true, message: '结算天数不能为空', trigger: 'blur'}
        ],
        settlementDay: [
          {required: true, message: '结算日不能为空', trigger: 'blur'}
        ]
      }
    }
  },
  watch: {
    form: {
      handler: function (n) {
        if (n.type == 3) {
          this.form.name = '现结'
        } else {
          this.form.name = this.dict.label.t_bas_settlement_type[n.type] + n.settlementDayCount + "天 结算日"+n.settlementDay
        }
      },
      deep: true

    }
  },
  updated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })},
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    changeName() {
      if (n.type == 3) {
        this.form.name = '现结'
      } else {
        this.form.name = this.dict.label.t_bas_settlement_type[n.type] + n.settlementDayCount + "天 结算日"+n.settlementDay
      }
    }

  }
}
</script>

<style scoped>
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
</style>
